import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase = "DBshop014_商品管理删除分类"

# 1.点击分类名称为“商品分类测试”后方的删除分类"链接

#打开dbshop的后台
firefox=openBrowser(urlAdmin)
#调用自定义函数进行后台的登录
DBshopLoginAdmin(firefox)
# 模拟鼠标操作，不能动鼠标
DBshopEnterMenu3(firefox,'商品管理','管理分类','商品分类')
# 点击“商品分类测试”后方的删除分类链接-plan A
# firefox.find_element_by_xpath('//td[contains(.,"%s")]/following-sibling::td[4]/a[3]'%goodsClassName).click()
# firefox.switch_to.alert.accept()
# time.sleep(5)
#

#
#
# # 断言
# try:
#     if firefox.find_element_by_xpath('//td[contains(.,"%s")]'%goodsClassName).is_displayed():
#         writeLog("%s 测试失败"%(testCase))
#     getPhoto(firefox)
# except:
#     writeLog("%s 测试通过" % (testCase))
# firefox.quit()
# 点击“商品分类测试”后方的删除分类链接-plan B
s14=firefox.find_elements_by_xpath('//table/tbody/tr/td[1]')
print(s14)
# 列表，无法直接使用text取文本
a14=[]
c14=[]


for i in s14:
    if goodsClassName in i.text:
        a14.append(i.text)
        print(a14)

for z in s14:
    c14.append(z.text)
print(c14)

b14=reGetString(a14[0],leftBinary=r"\(ID:",rightBinary=r"\)")
print(b14,type(b14))

firefox.find_element_by_xpath('//a[@onclick="return class_del_js(%s);"]'%b14).click()
firefox.switch_to.alert.accept()
time.sleep(5)



try:
    if b14 not in a14:
        writeLog("%s 测试通过"%(testCase))
except:
    writeLog("%s 测试失败" % (testCase))
    getPhoto(firefox)
firefox.quit()

